/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package expo43client;

import java.io.*;
import java.net.*;

/**
 *
 * @author TommySprat
 */
public class Expo43Client {

    static Socket e43Socket = null;
    static PrintWriter out = null;
    static BufferedReader in = null;
    static String HOST = "192.168.1.2";

    public static void main(String[] args) throws IOException, InterruptedException {

        Expo43ClientScoreServer scoreServer = new Expo43ClientScoreServer();
        scoreServer.start();
        
        Expo43ClientPlaylistServer playlistServer = new Expo43ClientPlaylistServer();
        playlistServer.start();

        expo43playlist.Expo43PlaylistApp expoPlaylist = new expo43playlist.Expo43PlaylistApp();
        expoPlaylist.main(new String[0]);

        expo43score.Expo43ScoreApp expoScoreboard = new expo43score.Expo43ScoreApp();
        expoScoreboard.main(new String[0]);

        try {
            e43Socket = new Socket(HOST, 4444);
            out = new PrintWriter(e43Socket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(e43Socket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + HOST);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: " + HOST + "\n Check if the IP adress is correct and the Expo43Menu is running there");
            System.exit(1);
        }

        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String fromServer;
        String toServer = null;

        while ((fromServer = in.readLine()) != null) {
            System.out.println("Server: " + fromServer);
            if (fromServer.equals("Bye.")) {
                break;
            }
            if (fromServer.equalsIgnoreCase("startgame")){
                scoreServer.startScoreboard();
            }
            if (fromServer.equalsIgnoreCase("stopgame")){
                scoreServer.stopScoreboard();
            }
            if (fromServer.equalsIgnoreCase("startplaylist")){
                playlistServer.startPlaylist();
            }
            if (fromServer.equalsIgnoreCase("stopplaylist")){
                playlistServer.stopPlaylist();
            }
            if (fromServer.equalsIgnoreCase("Scene1-Intro.wmv")){
                playlistServer.setScene("Scene1-Intro.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene2-Intro.wmv")){
                playlistServer.setScene("Scene2-Intro.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene3-SE.wmv")){
                playlistServer.setScene("Scene3-SE.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene4-GD.wmv")){
                playlistServer.setScene("Scene4-GD.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene5-HCD.wmv")){
                playlistServer.setScene("Scene5-HCD.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene6-ITM.wmv")){
                playlistServer.setScene("Scene6-ITM.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene7-SNE.wmv")){
                playlistServer.setScene("Scene7-SNE.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene8-TC.wmv")){
                playlistServer.setScene("Scene8-TC.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene9-ITGame.wmv")){
                playlistServer.setScene("Scene9-ITGame.wmv");
            }
            if (fromServer.equalsIgnoreCase("Scene10-Outtro.wmv")){
                playlistServer.setScene("Scene10-Outtro.wmv");
            }
            if (toServer != null) {
                System.out.println("Client: " + toServer);
                out.println(toServer);
            }
        }


        out.close();
        in.close();
        stdIn.close();
        e43Socket.close();
    }
}
